<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Eigen: Using BLAS/LAPACK from Eigen</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="eigendoxy.css" rel="stylesheet" type="text/css">
<!--  -->
<script type="text/javascript" src="eigen_navtree_hacks.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="Eigen_Silly_Professor_64x64.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname"><a href="http://eigen.tuxfamily.org">Eigen</a>
   &#160;<span id="projectnumber">3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)</span>
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.svg"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('TopicUsingBlasLapack.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">Using BLAS/LAPACK from Eigen </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Since Eigen version 3.3 and later, any F77 compatible BLAS or LAPACK libraries can be used as backends for dense matrix products and dense matrix decompositions. For instance, one can use <a href="http://eigen.tuxfamily.org/Counter/redirect_to_mkl.php">Intel® MKL</a>, Apple's Accelerate framework on OSX, <a href="http://www.openblas.net/">OpenBLAS</a>, <a href="http://www.netlib.org/lapack">Netlib LAPACK</a>, etc.</p>
<p>Do not miss this <a class="el" href="TopicUsingIntelMKL.html">page </a> for further discussions on the specific use of Intel® MKL (also includes VML, PARDISO, etc.)</p>
<p>In order to use an external BLAS and/or LAPACK library, you must link you own application to the respective libraries and their dependencies. For LAPACK, you must also link to the standard <a href="http://www.netlib.org/lapack/lapacke.html">Lapacke</a> library, which is used as a convenient think layer between Eigen's C++ code and LAPACK F77 interface. Then you must activate their usage by defining one or multiple of the following macros (<b>before</b> including any Eigen's header):</p>
<dl class="section note"><dt>Note</dt><dd>For Mac users, in order to use the lapack version shipped with the Accelerate framework, you also need the lapacke library. Using <a href="https://www.macports.org/">MacPorts</a>, this is as easy as: <div class="fragment"><div class="line">sudo port install lapack</div>
</div><!-- fragment --> and then use the following link flags: <code>-framework</code> <code>Accelerate</code> <code>/opt/local/lib/lapack/liblapacke</code>.dylib</dd></dl>
<table class="manual">
<tr>
<td><code>EIGEN_USE_BLAS</code> </td><td>Enables the use of external BLAS level 2 and 3 routines (compatible with any F77 BLAS interface) </td></tr>
<tr class="alt">
<td><code>EIGEN_USE_LAPACKE</code> </td><td>Enables the use of external Lapack routines via the <a href="http://www.netlib.org/lapack/lapacke.html">Lapacke</a> C interface to Lapack (compatible with any F77 LAPACK interface) </td></tr>
<tr>
<td><code>EIGEN_USE_LAPACKE_STRICT</code> </td><td>Same as <code>EIGEN_USE_LAPACKE</code> but algorithms of lower numerical robustness are disabled. <br  />
 This currently concerns only <a class="el" href="classEigen_1_1JacobiSVD.html" title="Two-sided Jacobi SVD decomposition of a rectangular matrix.">JacobiSVD</a> which otherwise would be replaced by <code>gesvd</code> that is less robust than Jacobi rotations. </td></tr>
</table>
<p>When doing so, a number of Eigen's algorithms are silently substituted with calls to BLAS or LAPACK routines. These substitutions apply only for <b>Dynamic</b> <b>or</b> <b>large</b> enough objects with one of the following four standard scalar types: <code>float</code>, <code>double</code>, <code>complex&lt;float&gt;</code>, and <code>complex&lt;double&gt;</code>. Operations on other scalar types or mixing reals and complexes will continue to use the built-in algorithms.</p>
<p>The breadth of Eigen functionality that can be substituted is listed in the table below. </p><table class="manual">
<tr>
<th>Functional domain</th><th>Code example</th><th>BLAS/LAPACK routines </th></tr>
<tr>
<td>Matrix-matrix operations <br  />
 <code>EIGEN_USE_BLAS</code> </td><td><div class="fragment"><div class="line">m1*m2.transpose();</div>
<div class="line">m1.selfadjointView&lt;<a class="code" href="group__enums.html#gga39e3366ff5554d731e7dc8bb642f83cdaf581029282d421eee5aae14238c6f749">Lower</a>&gt;()*m2;</div>
<div class="line">m1*m2.triangularView&lt;<a class="code" href="group__enums.html#gga39e3366ff5554d731e7dc8bb642f83cdafca2ccebb604f171656deb53e8c083c1">Upper</a>&gt;();</div>
<div class="line">m1.selfadjointView&lt;<a class="code" href="group__enums.html#gga39e3366ff5554d731e7dc8bb642f83cdaf581029282d421eee5aae14238c6f749">Lower</a>&gt;().rankUpdate(m2,1.0);</div>
<div class="ttc" id="agroup__enums_html_gga39e3366ff5554d731e7dc8bb642f83cdaf581029282d421eee5aae14238c6f749"><div class="ttname"><a href="group__enums.html#gga39e3366ff5554d731e7dc8bb642f83cdaf581029282d421eee5aae14238c6f749">Eigen::Lower</a></div><div class="ttdeci">@ Lower</div><div class="ttdef"><b>Definition:</b> Constants.h:211</div></div>
<div class="ttc" id="agroup__enums_html_gga39e3366ff5554d731e7dc8bb642f83cdafca2ccebb604f171656deb53e8c083c1"><div class="ttname"><a href="group__enums.html#gga39e3366ff5554d731e7dc8bb642f83cdafca2ccebb604f171656deb53e8c083c1">Eigen::Upper</a></div><div class="ttdeci">@ Upper</div><div class="ttdef"><b>Definition:</b> Constants.h:213</div></div>
</div><!-- fragment --></td><td><div class="fragment"><div class="line">?gemm</div>
<div class="line">?symm/?hemm</div>
<div class="line">?trmm</div>
<div class="line">dsyrk/ssyrk</div>
</div><!-- fragment --> </td></tr>
<tr class="alt">
<td>Matrix-vector operations <br  />
 <code>EIGEN_USE_BLAS</code> </td><td><div class="fragment"><div class="line">m1.adjoint()*b;</div>
<div class="line">m1.selfadjointView&lt;<a class="code" href="group__enums.html#gga39e3366ff5554d731e7dc8bb642f83cdaf581029282d421eee5aae14238c6f749">Lower</a>&gt;()*b;</div>
<div class="line">m1.triangularView&lt;<a class="code" href="group__enums.html#gga39e3366ff5554d731e7dc8bb642f83cdafca2ccebb604f171656deb53e8c083c1">Upper</a>&gt;()*b;</div>
</div><!-- fragment --></td><td><div class="fragment"><div class="line">?gemv</div>
<div class="line">?symv/?hemv</div>
<div class="line">?trmv</div>
</div><!-- fragment --> </td></tr>
<tr>
<td>LU decomposition <br  />
 <code>EIGEN_USE_LAPACKE</code> <br  />
 <code>EIGEN_USE_LAPACKE_STRICT</code> </td><td><div class="fragment"><div class="line">v1 = m1.lu().solve(v2);</div>
</div><!-- fragment --></td><td><div class="fragment"><div class="line">?getrf</div>
</div><!-- fragment --> </td></tr>
<tr class="alt">
<td>Cholesky decomposition <br  />
 <code>EIGEN_USE_LAPACKE</code> <br  />
 <code>EIGEN_USE_LAPACKE_STRICT</code> </td><td><div class="fragment"><div class="line">v1 = m2.selfadjointView&lt;<a class="code" href="group__enums.html#gga39e3366ff5554d731e7dc8bb642f83cdafca2ccebb604f171656deb53e8c083c1">Upper</a>&gt;().llt().solve(v2);</div>
</div><!-- fragment --></td><td><div class="fragment"><div class="line">?potrf</div>
</div><!-- fragment --> </td></tr>
<tr>
<td>QR decomposition <br  />
 <code>EIGEN_USE_LAPACKE</code> <br  />
 <code>EIGEN_USE_LAPACKE_STRICT</code> </td><td><div class="fragment"><div class="line">m1.householderQr();</div>
<div class="line">m1.colPivHouseholderQr();</div>
</div><!-- fragment --></td><td><div class="fragment"><div class="line">?geqrf</div>
<div class="line">?geqp3</div>
</div><!-- fragment --> </td></tr>
<tr class="alt">
<td>Singular value decomposition <br  />
 <code>EIGEN_USE_LAPACKE</code> </td><td><div class="fragment"><div class="line">JacobiSVD&lt;MatrixXd, ComputeThinV&gt; svd;</div>
<div class="line">svd.compute(m1);</div>
</div><!-- fragment --></td><td><div class="fragment"><div class="line">?gesvd</div>
</div><!-- fragment --> </td></tr>
<tr>
<td>Eigen-value decompositions <br  />
 <code>EIGEN_USE_LAPACKE</code> <br  />
 <code>EIGEN_USE_LAPACKE_STRICT</code> </td><td><div class="fragment"><div class="line">EigenSolver&lt;MatrixXd&gt; es(m1);</div>
<div class="line">ComplexEigenSolver&lt;MatrixXcd&gt; ces(m1);</div>
<div class="line">SelfAdjointEigenSolver&lt;MatrixXd&gt; saes(m1+m1.transpose());</div>
<div class="line">GeneralizedSelfAdjointEigenSolver&lt;MatrixXd&gt;</div>
<div class="line">    gsaes(m1+m1.transpose(),m2+m2.transpose());</div>
</div><!-- fragment --></td><td><div class="fragment"><div class="line">?gees</div>
<div class="line">?gees</div>
<div class="line">?syev/?heev</div>
<div class="line">?syev/?heev,</div>
<div class="line">?potrf</div>
</div><!-- fragment --> </td></tr>
<tr class="alt">
<td>Schur decomposition <br  />
 <code>EIGEN_USE_LAPACKE</code> <br  />
 <code>EIGEN_USE_LAPACKE_STRICT</code> </td><td><div class="fragment"><div class="line">RealSchur&lt;MatrixXd&gt; schurR(m1);</div>
<div class="line">ComplexSchur&lt;MatrixXcd&gt; schurC(m1);</div>
</div><!-- fragment --></td><td><div class="fragment"><div class="line">?gees</div>
</div><!-- fragment --> </td></tr>
</table>
<p>In the examples, m1 and m2 are dense matrices and v1 and v2 are dense vectors. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Thu Apr 21 2022 13:07:55 for Eigen by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
